import "../scss/index.scss";
import "../swiper/swiper.min.css";
import "../swiper/animate.min.css";
import "../css/iconfont/iconfont.css";

import * as Swiper from "../swiper/swiper.js";
import {WOW} from "../swiper/wow.js";

require ("swiper-animate-cn");

var swiperAnimateCache = require("swiper-animate-cn").swiperAnimateCache;
var swiperAnimate = require("swiper-animate-cn").swiperAnimate;
var clearSwiperAnimate = require("swiper-animate-cn").clearSwiperAnimate;

//整合首页用到的所有js
import { getIndex} from "./request.js";
// //引入懒加载
import { lazyLoad } from "../utils/lazyLoad.js";
import { partner } from "./common.js";

//调用合作伙伴图片--common里
partner();

//获取页面图片（不包含导航栏，页脚和合作伙伴里的图片）
let headerImg = document.querySelectorAll("header img")
let mainImg = document.querySelectorAll('main div:not(:last-child) img')
let Imgs = [...headerImg,...mainImg]
console.log(Imgs);

async function haha() {
  let res = await getIndex();
  console.log(res);
  let res2 = [];
  res.results.forEach(function(item){
    res2.push(item.photo_detal.url);
  })
  Imgs.forEach(function(item,index){
    item.setAttribute("data-src",res2[index])
  })

  //懒加载--括号里写需要懒加载的图片的类名
  lazyLoad(Imgs);
};
haha();


//宽高公式
function vw(w) {
  return (w / 1910) * 100 + "vw";
}

//导航栏吸顶
let nav = document.querySelector(".nav");
window.onscroll = function () {
  let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  scrollTop < 300 ? (nav.style.top = vw(-80)) : (nav.style.top = 0);
};

//轮播图  
let mySwiper = new Swiper(".swiper-container", {
  //切换效果
  effect: "cards",
  cardsEffect: {
    slideShadows: true,
    //transformEl:'.text',
  },
  //轮播图方向
  direction: "horizontal", //水平的

  //分页器 --轮播图的小点点
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },

  //配置上一页下一页按钮
          navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },

  //自动播放
  autoplay: {
    delay: 3000, //时间
    stopOnLastSlide: false, //是否在最后一张停止
    disableOnInteraction: true, //用户点击时停止播放
  },

  on: {
    init: function () {
      swiperAnimateCache(this); //隐藏动画元素
      swiperAnimate(this); //初始化完成开始动画
    },
    slideChangeTransitionEnd: function () {
      swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
      //this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次，去除ani类名
    },
  },
});

 //关于我们--按钮点击跳转页面
new WOW().init()
let button1 = document.querySelector('.button1')
button1.addEventListener('click',function(){
  window.location.href='./aboutme.html'
})

//video---点击遮罩消失
let video = document.querySelector('.video')
let hei2 = document.querySelector('.hei2')
video.addEventListener('click',function(){
    hei2.classList.toggle('animated')
    hei2.classList.toggle('fadeOutUp')
})


//case--点击遮罩消失,按钮添加跳转href
let heise1 = document.querySelector('.heise-1')
let hei = document.querySelector(".hei")

heise1.addEventListener('click',function(){
    hei.classList.toggle('animated')
    hei.classList.toggle('fadeOutUp')

})

let  button2 = document.querySelector('.button2')
button2.addEventListener('click',function(){
  window.location.href = './case.html'
})




